<script setup>
import { useRouteStore } from '@/pinia/tagsRoute'

const router = useRouter()
const route = useRoute()
const tagsStore = useRouteStore()

const refresh = inject('refresh')

const back = () => {
  tagsStore.deleteRoute(route)
  router.back(-1)
  setTimeout(() => {
    refresh()
  }, 30)
}

const to = path => {
  tagsStore.deleteRoute(route)
  router.replace({ path })
  setTimeout(() => {
    refresh()
  }, 30)
}

defineProps({
  title: {
    type: String,
    default: '返回上一页'
  }
})

defineExpose({
  back,
  to
})
</script>

<template>
  <el-button @click="back" icon="ArrowLeft">{{ $props.title }}</el-button>
</template>

<style scoped lang="scss"></style>
